package cn.toolck.minitomcat.runner;

import java.util.concurrent.*;

/**
 * @ClassName WorkExecutor
 * @Description connector处理请求的线程池，每个请求都有一个单独的线程去处理
 * @Author Toolck Rin
 * @Date 2021/3/17 23:09
 * @Version 1.0
 **/
public class WorkExecutor {
    private int corePoolSize = 10;
    private int maximumPoolSize = 50;
    private long keepAliveTime = 100L;
    private TimeUnit unit = TimeUnit.SECONDS;
    private BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(50);
    private ThreadFactory threadFactory = Executors.defaultThreadFactory();
    private RejectedExecutionHandler handler = new ThreadPoolExecutor.AbortPolicy();
    private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);

    public WorkExecutor() {
    }

    public void execute(Runnable command) {
        threadPoolExecutor.execute(command);
    }
}
